package com.jjb.www.ui.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.blankj.utilcode.util.SPUtils;
import com.hjq.base.BaseDialog;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.hjq.shape.view.ShapeTextView;
import com.hjq.widget.layout.WrapRecyclerView;
import com.jjb.www.R;
import com.jjb.www.app.AppActivity;
import com.jjb.www.http.api.AgencyListApi;
import com.jjb.www.http.api.LearningApi;
import com.jjb.www.http.model.HttpData;
import com.jjb.www.http.model.HttpList;
import com.jjb.www.ui.adapter.LearningAdapter;
import com.jjb.www.ui.dialog.LearningDialog;
import com.jjb.www.ui.dialog.RuleDialog;

/**
 *    author : Android CRG
 *    time   : 2018/10/18
 *    desc   : 承诺学习记录
 */
public class LearningRecordsActivity extends AppActivity {
    private ShapeTextView mTvAddTime;
    private ShapeTextView mTvTotalScore;
    private ShapeTextView mTvAlreadyTotalScore;
    private WrapRecyclerView mRvList;
    private Integer certId;
    private Integer card_book_id;
    private LearningAdapter adapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_learning_records;
    }

    @Override
    protected void initView() {
        mTvAddTime = findViewById(R.id.tv_add_time);
        mTvTotalScore = findViewById(R.id.tv_total_score);
        mTvAlreadyTotalScore = findViewById(R.id.tv_already_total_score);
        mRvList = findViewById(R.id.rv_list);
        adapter = new LearningAdapter(getContext());
        mRvList.setAdapter(adapter);
        mRvList.setLayoutManager(new LinearLayoutManager(getContext()));
        setOnClickListener(mTvAddTime);
    }

    @Override
    public void onClick(View view) {
        if (view==mTvAddTime){
            Intent intent = new Intent();
            intent.putExtra("card_book_id",card_book_id);
            intent.putExtra("certId",certId);
            intent.setClass(this,AddLearningActivity.class);
            startActivity(intent);
        }
    }

    @Override
    protected void initData() {
        if (SPUtils.getInstance().getBoolean("Checked")){
            new LearningDialog.Builder(getContext())
                    .setListener(new LearningDialog.OnListener() {
                        @Override
                        public void onCompleted(BaseDialog dialog) {
                        }

                        @Override
                        public void onCancel(BaseDialog dialog) {

                        }
                    }).show();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        certId = getInt("certId");
        EasyHttp.get(this)
                .api(new LearningApi()
                        .setId(certId))
                .request(new HttpCallback<HttpData<LearningApi.Bean>>(this) {

                    @Override
                    public void onSucceed(HttpData<LearningApi.Bean> data) {
                        card_book_id = data.getData().getInfo().getCard_book_id();
                        mTvTotalScore.setText(data.getData().getInfo().getXu_score()+"");
                        mTvAlreadyTotalScore.setText(data.getData().getInfo().getAlready_score());
                        adapter.setData(data.getData().getList());
                    }
                });
    }
}